<template>
  <!-- 搜索歌手 -->
  <div class="sc-artist">
    <search-not-found v-if="!found"></search-not-found>
    <div v-if="found">
      <div ref="artistMain" class="art-main">
        <ul class="art-main-list clearfix">
          <li class="art-main-item" v-for="item in artists" :key="item.id">
            <div class="artist-item-box">
              <div class="artist-item-cover">
                <a
                  href="javascript:;"
                  :title="item.name"
                  @click="clickArtistDetail(item.id)"
                >
                  <img
                    :src="item.img1v1Url"
                    :alt="item.name"
                    class="artist-item-pic"
                  />
                </a>
              </div>
              <h4 class="artist-name">
                <a
                  href="javascript:;"
                  :title="item.name"
                  class="artist-name-txt"
                  @click="clickArtistDetail(item.id)"
                >
                  {{ item.name }}</a
                >
              </h4>
            </div>
          </li>
        </ul>
      </div>
      <div class="artist-el-pagination" v-if="artistCount > 30">
        <el-pagination
          background
          @current-change="handleCurrentChange"
          :current-page.sync="currentPage"
          :page-size="30"
          layout="prev, pager, next, jumper"
          :total="artistCount"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import SearchNotFound from "views/search/child/SearchNotFound";

export default {
  components: {
    SearchNotFound,
  },
  data() {
    return {
      artists: [],
      currentPage: 1,
      artistCount: 0,
      found: true,
    };
  },
  mounted() {
    this.getSearchArtist();
  },
  methods: {
    clickArtistDetail(id) {
      this.playArtistDetail(id);
    },
    handleCurrentChange() {
      this.getSearchArtist();
      document.documentElement.scrollTo({
        top: 0,
        behavior: "smooth",
      });
    },
    getSearchArtist() {
      this.axios({
        url:
          "/cloudsearch?type=100&keywords=" +
          this.$store.state.MInput +
          "&offset=" +
          (this.currentPage - 1) * 30,
      })
        .then((res) => {
          // console.log(res);
          if (!res.data.result || res.data.code == 400) {
            this.found = false;
          } else {
            this.artists = res.data.result.artists;
            this.artistCount = res.data.result.artistCount;
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
};
</script>

<style>
.sc-artist {
  margin-bottom: 50px;
  padding: 20px;
  overflow: hidden;
}
.sc-artist .art-main-list {
  margin-right: -20px;
}
.sc-artist .art-main-item {
  float: left;
  width: 16.667%;
}
.sc-artist .artist-item-box {
  position: relative;
  top: 0;
  left: 0;
  right: 0;
  margin-right: 20px;
  margin-bottom: 20px;
}
.sc-artist .artist-item-cover {
  position: relative;
  display: block;
  overflow: hidden;
  padding-top: 100%;
  margin-bottom: 10px;
}
.sc-artist .artist-item-pic {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}
.sc-artist .artist-name {
  overflow: hidden;
}
.sc-artist .artist-name a:hover {
  color: var(--color-theme);
}
.sc-artist .artist-name-txt {
  font-size: 14px;
  float: left;
  width: 100%;
  font-weight: 400;
  overflow: hidden;
  text-overflow: ellipsis;
  height: 32px;
  line-height: 32px;
  white-space: nowrap;
}
.sc-artist .artist-el-pagination {
  position: relative;
  text-align: center;
  margin: 20px auto;
}
</style>